function ResetPassword(param) {
try{
	var that = this;
	
	this.j_rp_form = null;
	this.j_rp_new = null;
	this.j_rp_re_new = null;
	this.j_rp_new_error_msg = null;
	this.j_rp_re_new_error_msg = null;
	this.j_rp_submit = null;
	
	var new_password_correct = false;
	var re_new_password_correct = false;
	
	var new_password_validation_locked = true;
	var re_new_password_validation_locked = true;
	
	var new_password_validation_ever_opened = false;
	var re_new_password_validation_ever_opened = false;
	
	var form_submiting = false;
	
	function __construct(p) {
	try{
		for(pkey in p) {
			if(pkey[0] != "_") {
				that[pkey] = p[pkey];
			}
		}
		
		that.j_rp_form.submit(editFormSubmit);
		that.j_rp_submit.mousedown(editSumbitMousedown);
		
		that.j_rp_new.blur(newPasswordInputBlur);
		that.j_rp_re_new.blur(reNewPasswordInputBlur);
		
		that.j_rp_new.change(newPasswordInputChange);
		that.j_rp_re_new.change(reNewPasswordInputChange);
		
	}catch(err) {
		alert(err);
	}
	}
	
	function newPasswordInputChange() {
	try{
		if(new_password_validation_locked) {
			new_password_validation_locked = false;
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function newPasswordInputBlur() {
	try{
		if(!form_submiting) {
			validateNewPassword();
			//validateReNewPassword();
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function reNewPasswordInputChange() {
		try{
			if(re_new_password_validation_locked) {
				re_new_password_validation_locked = false;
			}
		}catch(err) {
			alert(err);
		}
	}
	
	function reNewPasswordInputBlur() {
		try{
			if(!form_submiting) {
				validateReNewPassword();
			}
		}catch(err) {
			alert(err);
		}
	}
	
	function validateNewPassword() {
	try{
		if(!new_password_validation_locked) {
			new_password_validation_locked = true;
	    	if(!new_password_validation_ever_opened) {
	    		new_password_validation_ever_opened = true;
	    	}
			
			var newPassword = that.j_rp_new.val();
			var newPassLength = jq.trim(newPassword).length;
			
			// check required
			if(!newPassLength) {
				new_password_correct = false;
				that.j_rp_new.data({ 'errorMsg' : "Value required" });
				showWarningMsg(that.j_rp_new, that.j_rp_new_error_msg);
				return false;
			}
			// check minimum length
			if(newPassLength < 8) {
				new_password_correct = false;
				that.j_rp_new.data({ 'errorMsg' : "At least 8 characters" });
				showWarningMsg(that.j_rp_new, that.j_rp_new_error_msg);
				return false;
			}
			// check maximum length
			if(newPassLength > 20) {
				new_password_correct = false;
				that.j_rp_new.data({ 'errorMsg' : "Less than 20 characters" });
				showWarningMsg(that.j_rp_new, that.j_rp_new_error_msg);
				return false;
			}
			// check regex
			if(newPassword.search(/^[a-zA-Z0-9_]{6,20}$/) == -1) {
				new_password_correct = false;
				that.j_rp_new.data({ 'errorMsg' : "Not a valid password" });
				showWarningMsg(that.j_rp_new, that.j_rp_new_error_msg);
				return false;
			}
			
			new_password_correct = true;
			removeWarningMsg(that.j_rp_new, that.j_rp_new_error_msg);
			
		}else {
			// do nothing
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function validateReNewPassword() {
	try{
		if(!re_new_password_validation_locked) {
			// once open, never lock
	    	if(!re_new_password_validation_ever_opened) {
	    		re_new_password_validation_ever_opened = true;
	    	}
	    	
			var reNewPassword = that.j_rp_re_new.val();
			var reNewPassLength = jq.trim(reNewPassword).length;

			// check required
			if(!reNewPassLength) {
				re_new_password_correct = false;
				that.j_rp_re_new.data({ 'errorMsg' : "Value required" });
				showWarningMsg(that.j_rp_re_new, that.j_rp_re_new_error_msg);
				return false;
			}
			
			var newPassword = that.j_rp_new.val();
			
			if(newPassword != reNewPassword) {
				re_new_password_correct = false;
				that.j_rp_re_new.data({ 'errorMsg' : "Passwords do not match" });
				showWarningMsg(that.j_rp_re_new, that.j_rp_re_new_error_msg);
				return false;
			}
			re_new_password_correct = true;
			removeWarningMsg(that.j_rp_re_new, that.j_rp_re_new_error_msg);
		}
	}catch(err) {
		//alert(err);
	}
	}
	
	function editSumbitMousedown(e) {
	try{
		form_submiting = true;
		
	}catch(err) {
		alert(err);
	}
	}
	
	function editFormSubmit(e) {
	try{
    	e.preventDefault();
    	
    	if(!new_password_validation_ever_opened) {
    		new_password_validation_ever_opened = true;
			new_password_validation_locked = false;
    	}
    	if(!re_new_password_validation_ever_opened) {
        	re_new_password_validation_ever_opened = true;
    		re_new_password_validation_locked = false;
    	}
    	

		var rpForm = this;

    	validateNewPassword();
    	validateReNewPassword();

		form_submiting = false;
		if(new_password_correct && re_new_password_correct) {
			rpForm.submit();
			return true;
		}
		return false;
    	
	}catch(err) {
		alert(err);
	}
	}

	function showWarningMsg(inputEl, errEl) {
	try{
		if (!inputEl.hasClass("error")){
			inputEl.addClass("error");
		}
		errEl.text(inputEl.data("errorMsg"));
		if(!errEl.is(":visible")) {
			errEl.show();
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function removeWarningMsg(inputEl, errEl) {
	try{
		if(inputEl.hasClass("error")) {
			inputEl.removeClass("error");
		}
		if(errEl.is(":visible")) {
			errEl.hide();
		}
	}catch(err) {
		alert(err);
	}
	}
	
	__construct(param);
	
	
}catch(err) {
	alert(err);
}
}
